package com.example.demo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2 //开启swagger
public class SwaggerConfig {
    @Bean
    public Docket docket1(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("喜欢");
    }
    @Bean
    public Docket docket2(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("多云");
    }
    //配置Docket文档
    @Bean
    public Docket docket(Environment environment){
        Profiles profiles=Profiles.of("dev","test");
        //通过environment.acceptsProfiles监听是否处于在自己配置的环境中
        boolean target=environment.acceptsProfiles(profiles);
        return new Docket(DocumentationType.SWAGGER_2)
                //配置基本信息
                .apiInfo(apiInfo())
                .groupName("tianqili")
                // false 禁止启动swagger
                .enable(target)
                //下面三个为一套
                .select()
                //扫描指定的包
                .apis(RequestHandlerSelectors.basePackage("com.example.demo.controller"))
                .build();
    }
    public ApiInfo apiInfo(){
        Contact contact=new Contact("田起立","http://www.baidu.com","3193920282@qq.com");
        return new ApiInfo(
                "田起立大人无敌",
                "喜欢多云的季节",
                "1.0",
                "http://www.baidu.com",
                 contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }
}
